/**
 * @author yxw
 * date : 2013年11月3日 下午4:57:39 
 */
package com.tzinfo.tzt.activity;

import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.TabHost;

import com.tzinfo.tzt.R;
import com.tzinfo.tzt.activity.util.MyApplication;
import com.umeng.analytics.MobclickAgent;
import com.umeng.update.UmengUpdateAgent;

public class MyFabuActivity extends TabActivity implements OnClickListener{

	private TabHost tabHost;
	private RadioGroup radioGroup;
	private Resources resources;
	private MyApplication mApp;
	private Button backBtn;
	
	
	@Override
	protected void onStart() {
		// TODO Auto-generated method stub
		super.onStart();

		if (mApp.isExit()) {
			finish();
		}
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_my_fabu);
		init();
	}

	private void init() {
		mApp = (MyApplication) getApplication();
		mApp.setExit(false);
		backBtn=(Button) this.findViewById(R.id.bt_back);
		backBtn.setOnClickListener(this);
		resources = getBaseContext().getResources();

		tabHost = getTabHost();
		tabHost.addTab(tabHost.newTabSpec("tab1")
				.setIndicator("TAB1")
				.setContent(new Intent(this, MyOldPubListActivity.class)));
		tabHost.addTab(tabHost.newTabSpec("tab2")
				.setIndicator("TAB2")
				.setContent(new Intent(this, MyRentPubListActivity.class)));

		radioGroup = (RadioGroup) findViewById(R.id.rgroup_under_top);

		radioGroup.setOnCheckedChangeListener(checkedChangeListener);

		Intent intent = getIntent();
		int no = intent.getIntExtra("TabNo", 0);
		switch (no) {
		case 2:
			tabHost.setCurrentTabByTag("tab2");
			((RadioButton) (radioGroup.getChildAt(1))).setChecked(true);
			
			break;
		default:
			tabHost.setCurrentTabByTag("tab1");
			((RadioButton) (radioGroup.getChildAt(0))).setChecked(true);
			break;
		}

		UmengUpdateAgent.setUpdateOnlyWifi(false);
		UmengUpdateAgent.update(this);
		UmengUpdateAgent.setUpdateAutoPopup(true);
	}
	
	private OnCheckedChangeListener checkedChangeListener = new OnCheckedChangeListener() {
		public void onCheckedChanged(RadioGroup group, int checkedId) {
			switch (checkedId) {
			case R.id.radio_top_btn1:
				tabHost.setCurrentTabByTag("tab1");
				break;
			case R.id.radio_top_btn2:
				tabHost.setCurrentTabByTag("tab2");
				break;
			}
		}
	};
	public void goFabu(View v){
		Intent intent =new Intent(this, MyFabuUpdateActivity.class);
		startActivity(intent);
	}
	public void onResume() {
		super.onResume();
		MobclickAgent.onResume(this);
	}

	public void onPause() {
		super.onPause();
		MobclickAgent.onPause(this);
	}

	@Override
	public void onClick(View view) {
		switch (view.getId()) {
		case R.id.bt_back:
			this.finish();
			break;

		default:
			break;
		}
		
	}
}
